package com.manopservice.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.manopservice.model.CarAutoPartPic;


@Repository("carAutoPartPicDAO")
public class CarAutoPartPicDAOImpl implements CarAutoPartPicDAO{

	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public void save(CarAutoPartPic carAutoPartPic) {
		sessionFactory.getCurrentSession().saveOrUpdate(carAutoPartPic);
		
	}

	@Override
	public void delete(int id) {
		CarAutoPartPic carAutoPartPic = (CarAutoPartPic) sessionFactory.getCurrentSession().get(CarAutoPartPic.class, id);
		sessionFactory.getCurrentSession().delete(carAutoPartPic);
		
	}

	@SuppressWarnings("unchecked")
	public List<CarAutoPartPic> findAll() {
		
		return (List<CarAutoPartPic>) sessionFactory.getCurrentSession().createCriteria(CarAutoPartPic.class).list();
	}

	@Override
	public CarAutoPartPic findById(int id) {

		return (CarAutoPartPic) sessionFactory.getCurrentSession().get(CarAutoPartPic.class, id);
	}

}
